﻿fs.util.pageLoadFunction.push(function () {
    firstColumns = [//style: "fs_disable", hide: true,
{index: 0, headerText: "YTDM-1", style: "fs_disable", hide: true, reference: true, edit: true, style: 'gray', readonly: true, width: 80, rowText: "YTDM_1",
expression: function (row) {
    if (fs.form.month == 1)
        row[this.rowText] = 0;
    else
        return row[this.rowText] = getLastMonthFieldData(row.accountcode, "YTD", row.digits);
}
},
{ index: 1, headerText: "Last Month", reference: true, edit: true, style: 'green', readonly: true, width: 80, rowText: "LM",
    expression: function (row) {
        if (fs.form.month == 1)
            row[this.rowText] = 0;
        else
            return row[this.rowText] = getLastMonthFieldData(row.accountcode, "CM", row.digits);
    }
},
{ index: 2, headerText: "YTD", edit: true, style: 'blue', readonly: true, width: 80, rowText: "YTD" },
{ index: 3, headerText: "Current Month", edit: true, style: '', width: 80, rowText: "CM" }

];
    window.BeforStartMergeServices = function (callback) {

        var opt = {
            Month: fs.form.month,
            Year: fs.form.year,
            Currency: "RMB",
            WithCurrentMonth:false,
            Type: "",
            Data: "",
            ListTitle: "R_Flash_HR",
            CompanyCode: "Asia",
            ActionType: "Calc"
        };
        refrenceData.receive(opt, function (data) {
            window.CM_HR01060100 = JSON.parse(data.Data).CM_HR01060100;
            window.CM_HR01060101 = JSON.parse(data.Data).CM_HR01060101;
            window.CM_HR01060102 = JSON.parse(data.Data).CM_HR01060102;
            window.CM_HR01010100 = JSON.parse(data.Data).CM_HR01010100;
            callback();
        }, "&fields=CM_HR01060100,CM_HR01060101,CM_HR01060102,CM_HR01010100");
    }
});

var afterBindingEvent = function () {

    if (!window.AllCurrentYearItemsCompressObject)
        window.AllCurrentYearItemsCompressObject = getPassMonthCompressObject();


    var self = this;
    //    if (fs.form.month > 1) {
    //        var newCMValue = ((parseFloat(unWarpValue(self['LM'])) + parseFloat(unWarpValue(self['CM']))) / 2).toFix(self.digits);
    //        self['CM'] = ko.observable(newCMValue);
    //    }

    var refIdentity = self.accountcode.replace("HR0102", "HR0101");
    var refRow = viewModel.items().filter(function (r) { return r.accountcode == refIdentity })[0];

    var CompressRow = AllCurrentYearItemsCompressObject.filter(function (obj) { return obj.accountcode == refIdentity })[0];
     
    self["YTD"] = ko.computed(function () {
        if (fs.form.month == 1)
            return parseFloat(unWarpValue(refRow['CM'])).toFix(self.digits);
        else
            return ((parseFloat(unWarpValue(refRow['CM'])) + parseFloat(unWarpValue(CompressRow['CM']))) / fs.form.month).toFix(self.digits);
    })
}

var headCountAfterBinding = function () {
    var self = this;
    
    self["YTD"] = ko.computed(function () {
        return parseFloat(unWarpValue(self['CM'])).toFix(self.digits);
    })

}

var readyJSON = [
{ accountcode: "HR01010100", unit: "number", afterBinding: headCountAfterBinding, description: "Roquette Headcount-month end", datarow: true, bold: true, index: 0, exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "to",
        start: "HR01010101",
        end: "HR01010106",
        equ: "+"
    }
}]
},
{ accountcode: "HR01010101", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Operations", datarow: true },
{ accountcode: "HR01010102", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Sales", datarow: true },
{ accountcode: "HR01010103", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Logistics", datarow: true },
{ accountcode: "HR01010104", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "GMU", datarow: true },
{ accountcode: "HR01010105", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Administration/Corporate", datarow: true },
{ accountcode: "HR01010106", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "R&D", datarow: true },
{ emptyrow: true, description: "" },
{ accountcode: "HR01010200", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Temp Headcount-month end", datarow: true, bold: true },
{ emptyrow: true, description: "" },
{ accountcode: "HR01010301", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Direct", datarow: true, bold: true },
{ emptyrow: true, description: "" },
{ accountcode: "HR01010302", unit: "number", afterBinding: headCountAfterBinding, exchangerate: false, description: "Indirect", datarow: true, bold: true },
{ accountcode: "Control", description: "HR01010100=HR01010301+HR01010302", index: 0, exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01010100", "HR01010301", "HR01010302"],
        equ: ["-(", "+", ")+"]
    }
}], controlrow: true
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01020100", unit: "number", digits: 1, exchangerate: false, description: "Roquette Full Time Equivalent-month", datarow: true, bold: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020101", unit: "number", digits: 1, exchangerate: false, description: "Operations", datarow: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020102", unit: "number", digits: 1, exchangerate: false, description: "Sales", datarow: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020103", unit: "number", digits: 1, exchangerate: false, description: "Logistics", datarow: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020104", unit: "number", digits: 1, exchangerate: false, description: "GMU", datarow: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020105", unit: "number", digits: 1, exchangerate: false, description: "Administration/Corporate", datarow: true, afterBinding: afterBindingEvent },
{ accountcode: "HR01020106", unit: "number", digits: 1, exchangerate: false, description: "R&D", datarow: true, afterBinding: afterBindingEvent },
{ emptyrow: true, description: "" },
{ accountcode: "HR01020200", unit: "number", digits: 1, exchangerate: false, description: "Temp Full Time Equivalent-month", datarow: true, bold: true, afterBinding: afterBindingEvent },
{ emptyrow: true, description: "" },
{ emptyrow: true, description: "" },
{ emptyrow: true, description: "" }, 
{ accountcode: "HR01030101", unit: "hour", exchangerate: false, description: "Roquette-Working hours-Excl. OT", datarow: true, index: 0, ProcessTODO: "=HR01020100x8" },
{ accountcode: "HR01030102", unit: "hour", exchangerate: false, description: "Temp-Working hours-Excl. OT", datarow: true, index: 0, ProcessTODO: "=HR01020200x8" },
{ accountcode: "HR01030100", unit: "hour", description: "Total-working hour-Excl. OT", datarow: true, bold: true, index: 0, exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01030101", "HR01030102"],
        equ: "+"
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01040101", unit: "hour", exchangerate: false, description: "Roquette-Overtime hours", datarow: true },
{ accountcode: "HR01040102", unit: "hour", exchangerate: false, description: "Temp-Overtime hours", datarow: true },
{ accountcode: "HR01040100", unit: "hour", description: "Total -Overtime hours", datarow: true, bold: true, index: 0, exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01040101", "HR01040102"],
        equ: "+"
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01050100", unit: "hour", description: "Total working hours", datarow: true, bold: true, index: 0, exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01030100", "HR01040100"],
        equ: "+"
    }
}]
},

{ emptyrow: true, description: "" },
{ accountcode: "HR01060100", description: "Headcount-Turnover", datarow: true, bold: true, unit: "number", exchangerate: false,Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01060101", "HR01060102"],
        equ: "+"
    }
}]
},
{ accountcode: "HR01060101", exchangerate: false, description: "voluntary", datarow: true, unit: "number" },
{ accountcode: "HR01060102", exchangerate: false, description: "Involuntary", datarow: true, unit: "number" },
{ emptyrow: true, description: "" },
{ accountcode: "HR01070100", hasProcess: true, description: "Turnover Ratio(Month/12MR)", digits: 1, datarow: true, unit: "%", exchangerate: false,Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060100", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060100", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060100)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ accountcode: "HR01070101", hasProcess: true, description: "Voluntary ratio(Month/12MR)", digits: 1, datarow: true, unit: "%", exchangerate: false,Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060101", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true

    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060101", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060101)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ accountcode: "HR01070102", hasProcess: true, description: "Involuntary ratio(Month/12MR)", digits: 1, datarow: true, unit: "%", exchangerate: false,Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060102", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060102", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060102)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01080100", exchangerate: false, description: "Training hours", datarow: true, unit: "Number" },
{ accountcode: "HR01090100", exchangerate: false, description: "Number of promotion", datarow: true, unit: "Number" }
];
